import Vue from 'vue'
import Vuex from 'vuex'
import vuexPersist from 'vuex-persistedstate';
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    historyList:[]
  },
  mutations: {
    addhistory(state,val){
      let bool = state.historyList.some(item => item == val);
      if (bool){
        return;
      }
      if (state.historyList.length == 5){
        state.historyList.splice(4,1);
        // unshift 往数组的开头添加数据
        state.historyList.unshift(val);
      } else {
        state.historyList.push(val)
      }
      
    },
    clear(state){
      state.historyList = [];
    }
  },
  actions: {
  },
  modules: {
  },
  plugins: [
    new vuexPersist({
      storage: window.localStorage,
    })
  ],
})
